package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.domain.ZhDeptInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.service.IZhDeptInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.system.domain.ZhHotSearch;
import com.ruoyi.system.service.IZhHotSearchService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 热搜 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-05-02
 */
@Controller
@RequestMapping("/system/zhHotSearch")
public class ZhHotSearchController extends BaseController
{
    private String prefix = "system/zhHotSearch";
	
	@Autowired
	private IZhHotSearchService zhHotSearchService;

	@Autowired
	private IZhDeptInfoService zhDeptInfoService;

	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhHotSearch:view")
	@GetMapping()
	public String zhHotSearch(ZhHotSearch zhHotSearch,ModelMap mmap)
	{
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhHotSearch.getParams())));
		return prefix + "/zhHotSearch";
	}
	
	/**
	 * 查询热搜列表
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhHotSearch:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ZhHotSearch zhHotSearch)
	{
		startPage();
        List<ZhHotSearch> list = zhHotSearchService.selectZhHotSearchList(zhHotSearch);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出热搜列表
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhHotSearch:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZhHotSearch zhHotSearch)
    {
    	List<ZhHotSearch> list = zhHotSearchService.selectZhHotSearchList(zhHotSearch);
        ExcelUtil<ZhHotSearch> util = new ExcelUtil<ZhHotSearch>(ZhHotSearch.class);
        return util.exportExcel(list, "zhHotSearch");
    }
	
	/**
	 * 新增热搜
	 */
	@RequiresPermissions("system:zhHotSearch:add")
	@DataScope(tableAlias = "l")
	@GetMapping("/add")
	public String add(ZhHotSearch zhHotSearch,ModelMap mmap)
	{
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhHotSearch.getParams())));
		return prefix + "/add";
	}
	
	/**
	 * 新增保存热搜
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhHotSearch:add")
	@Log(title = "热搜", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ZhHotSearch zhHotSearch)
	{		
		return toAjax(zhHotSearchService.insertZhHotSearch(zhHotSearch));
	}

	/**
	 * 修改热搜
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhHotSearch:edit")
	@GetMapping("/edit/{id}")
	public String edit(ZhHotSearch zhHotSearch,@PathVariable("id") Integer id, ModelMap mmap)
	{

		ZhHotSearch result = zhHotSearchService.selectZhHotSearchById(id);
		mmap.put("zhHotSearch", result);
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhHotSearch.getParams())));
		return prefix + "/edit";
	}
	
	/**
	 * 修改保存热搜
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhHotSearch:edit")
	@Log(title = "热搜", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ZhHotSearch zhHotSearch)
	{		
		return toAjax(zhHotSearchService.updateZhHotSearch(zhHotSearch));
	}
	
	/**
	 * 删除热搜
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhHotSearch:remove")
	@Log(title = "热搜", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(ZhHotSearch zhHotSearch,String ids)
	{		
		return toAjax(zhHotSearchService.deleteZhHotSearchByIds(ids));
	}
	
}
